#ifndef LCD_UC1609C
#define LCD_UC1609C

// UC1609C 192*64 LCM 的 AVR 驱动。
// 本驱动需要根据接线修改端口设置，设置在configure.h
// 源代码发布在  https://gitee.com/redpower/uc1609c_avr
// 木兰开放许可协议


// Macro Define
#ifndef uchar 
#define uchar unsigned char
#endif

#ifndef uint
#define uint unsigned int
#endif

#ifndef FALSE 
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef swap
#define swap(a, b) \
  {                \
    int16_t t = a; \
    a = b;         \
    b = t;         \
  }
#endif

//接口驱动部分(lcd开头)
//LCD 初始化
void lcd_init(void);
//使用某种模式填充屏幕，
//默认array可以用DarkScreen 和 BrightScreen ，也可以自定义
void lcd_format_screen(uchar array[]);
//设置暗背景
void lcd_set_dark();

//设置亮背景
void lcd_set_bright();

//显示16x16 点阵图像、汉字、生僻字或16x16 点阵的其他图标
void lcd_display_16x16(uchar page, uchar column, uchar *dp);

//显示32x64 点阵图像、汉字、生僻字或32x64 点阵的其他图标
void lcd_display_32x64(uchar page, uchar column, uchar *dp);

// Desc: draws passed character.
// Param1: character 'A' or number in  the ASCII table 1-127(default)
void lcd_put_char_7x5(uchar page, uchar column, char character);

//指定坐标显示一个6*8字符串
void lcd_put_chars_7x5(uchar page, uchar column, char *data_s);

//显示8*16点阵ASCII字符函数
void lcd_put_char_16x8(uchar page, uchar column, char char_data);

//指定坐标显示一个16*8字符串
void lcd_put_chars_16x8(uchar page, uchar column, char *data_s);

// Desc: invert the display
// Param1: bits, 1 invert , 0 normal
void lcd_invert_display(uchar is_invert);

// Desc: turns in display
// Param1: bits 1  on , 0 off
void lcd_enable(uint8_t bits);


// Desc: Scroll the displayed image up by SL rows.
//The valid SL value is between 0 (for no
//scrolling) and (64).
//Setting SL outside of this range causes undefined effect on the displayed
//image.
// Param1: bits 0-64 line number y-axis
void lcd_scroll(uint8_t bits);


// Desc: Rotates the display
// Set LC[2:1] for COM (row) mirror (MY), SEG (column) mirror (MX).
// Param1: 4 possible values 000 010 100 110 (defined)
// If Mx is changed the buffer must BE updated
void lcd_rotate(uint8_t rotatevalue);

// Desc: turns on all Pixels
// Param1: bits Set DC[1] to force all SEG drivers to output ON signals
// 1 all on ,  0 all off
void lcd_all_pixels_on(uint8_t bits);

// Desc: Fill the screen NOT the buffer with a datapattern
// Param1: datapattern can be set to zero to clear screen (not buffer) range 0x00 to 0ff
// Param2: optional delay in microseconds can be set to zero normally.
void lcd_fill_screen(uint8_t dataPattern);

//Desc: Draw a bitmap to the screen
//Param1: x offset 0-192
//Param2: y offset 0-64
//Param3: width 0-192
//Param4 height 0-64
//Param5 the bitmap
void lcd_draw_bitmap_p(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t *data); //使用程序存储器

//Desc: Draw a bitmap to the screen
//Param1: x offset 0-192
//Param2: y offset 0-64
//Param3: width 0-192
//Param4 height 0-64
//Param5 the bitmap
void lcd_draw_bitmap_mem(int16_t x, int16_t y, uint8_t w, uint8_t h, uint8_t *data); //使用内存

void lcd_write_raw(uchar data1);
void lcd_write_cmd(uchar command);
void lcd_write_data(uchar data1);
void lcd_write_cmd_ex(uint8_t command, uint8_t value);


//图形部分(graphics开头)

//清除图形显示缓冲区
void graphics_clear_buf();
//将缓冲区数据刷新到lcd
void graphics_update();

void graphics_draw_pixel(int16_t x, int16_t y, uint16_t colour);


// Draw a circle outline
void graphics_draw_circle(int16_t x0, int16_t y0, int16_t r,
                uint16_t color);

void graphics_draw_circle_helper(int16_t x0, int16_t y0,
                      int16_t r, uint8_t cornername, uint16_t color);

void graphics_fill_circle(int16_t x0, int16_t y0, int16_t r,
                uint16_t color);

// Used to do circles and roundrects
void graphics_fill_circle_helper(int16_t x0, int16_t y0, int16_t r,
                      uint8_t cornername, int16_t delta, uint16_t color);

// Bresenham's algorithm - thx wikpedia
void graphics_draw_line(int16_t x0, int16_t y0,
              int16_t x1, int16_t y1,
              uint16_t color);

// Draw a rectangle
void graphics_draw_rect(int16_t x, int16_t y,
              int16_t w, int16_t h,
              uint16_t color);


void graphics_draw_fast_vline(int16_t x, int16_t y,
                   int16_t h, uint16_t color);

void graphics_draw_fast_hline(int16_t x, int16_t y,
                   int16_t w, uint16_t color);


void graphics_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h,
              uint16_t color);

void graphics_fill_screen(uint16_t color);


// Draw a rounded rectangle
void graphics_draw_round_rect(int16_t x, int16_t y, int16_t w,
                   int16_t h, int16_t r, uint16_t color);

// Fill a rounded rectangle
void graphics_fill_round_rect(int16_t x, int16_t y, int16_t w,
                   int16_t h, int16_t r, uint16_t color);


// Draw a triangle
void graphics_draw_triangle(int16_t x0, int16_t y0,
                  int16_t x1, int16_t y1,
                  int16_t x2, int16_t y2, uint16_t color);


// Fill a triangle
void graphics_fill_triangle(int16_t x0, int16_t y0,
                  int16_t x1, int16_t y1,
                  int16_t x2, int16_t y2, uint16_t color);

void graphics_draw_bitmap(int16_t x, int16_t y,
                const uint8_t *bitmap, int16_t w, int16_t h,
                uint16_t color);

// Draw a 1-bit color bitmap at the specified x, y position from the
// provided bitmap buffer (must be PROGMEM memory) using color as the
// foreground color and bg as the background color.
void graphics_draw_bitmap_ex(int16_t x, int16_t y,
                   const uint8_t *bitmap, int16_t w, int16_t h,
                   uint16_t color, uint16_t bg);


//Draw XBitMap Files (*.xbm), exported from GIMP,
//Usage: Export from GIMP to *.xbm, rename *.xbm to *.c and open in editor.
//C Array can be directly used with this function
void graphics_draw_xbitmap(int16_t x, int16_t y,
                 const uint8_t *bitmap, int16_t w, int16_t h,
                 uint16_t color);

// Draw a character
void graphics_draw_char(int16_t x, int16_t y, unsigned char c,
              uint16_t color, uint16_t bg, uint8_t size);


#endif
